#ifndef STR_OP_H
#define STR_OP_H

#include <algorithm>
#include <string>

inline int indexOf(char c, const char *buf, size_t length, int start = 0)
{
    int pos = start;
    while(pos < length && buf[pos] != c)
    {
        ++pos;
    }
    return (pos == length) ? -1 : pos;
}

inline void trim(std::string &str)
{
    size_t endpos = str.find_last_not_of(" \t\n");
    size_t startpos = str.find_first_not_of(" \t\n");
    if(std::string::npos != endpos)
    {
        str = str.substr( 0, endpos+1 );
        str = str.substr( startpos );
    }
    else
    {
        str.erase(std::remove(std::begin(str), std::end(str), ' '),
                  std::end(str));
    }
}


#endif // STR_OP_H
